﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using MDM.GUI.MDM.Business;

namespace MDM.GUI
{
    public partial class LoginForm : DevExpress.XtraEditors.XtraForm
    {
        public LoginForm()
        {
            InitializeComponent();
        }
        private void LoginForm_Load(object sender, EventArgs e)
        {

        }
        private bool ValidateForm()
        {
            if (txtAccount.Text.Length < 50 && txtAccount.Text.Length > 6 && txtPassword.Text.Length < 50 && txtPassword.Text.Length > 6)
            {
                return true;
            }
            return false;
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //ktra gia tri nhap vao
            if (ValidateForm() == false)
                MessageBox.Show("Nhap sai, Nhap lai");
            else
            {
                //ktra User

                int iCheck = UserController.ValidateUser(txtAccount.Text, txtPassword.Text);

                //bool blCheckUserInfor = MDM.Business.UserController.checkUser(txtAccount.Text, txtPassword.Text);
                //dung thi dong LoginForm lai
                if (iCheck ==1)
                {
                    this.Close();
                }
                //sai nhap lai
                else
                {

                    MessageBox.Show("Dang Nhap That Bai, Dang Nhap lai");
                }
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            Application.Exit();
           // this.Close();
        }

        private void LoginForm_KeyPress(object sender, KeyPressEventArgs e)
        {
            
            
        }

        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData==Keys.Enter)
            {
                if (ValidateForm() == false)
                    MessageBox.Show("Nhap sai, Nhap lai");
                else
                {
                    //ktra User

                    int iCheck = UserController.ValidateUser(txtAccount.Text, txtPassword.Text);

                    //bool blCheckUserInfor = MDM.Business.UserController.checkUser(txtAccount.Text, txtPassword.Text);
                    //dung thi dong LoginForm lai
                    if (iCheck == 1)
                    {
                        this.Close();
                    }
                    //sai nhap lai
                    else
                    {

                        MessageBox.Show("Dang Nhap That Bai, Dang Nhap lai");
                    }
                }
            }
        }
    }
}